package com.loveyukari.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.loveyukari.model.Auth;
import com.loveyukari.model.Register;
import com.loveyukari.service.NewRegisterService;
import com.loveyukari.support.JsonResult;

import net.sf.json.JSONObject;

/**
*
*yangshaohua
*2017年1月21日下午1:48:51
**/
@RequestMapping("/admin/register")
@Controller
public class RegisterController {
	@Autowired
	private NewRegisterService newRegisterService;
	
	@RequestMapping("/index")
	public String index(Model model){
		List<Auth> authList = newRegisterService.getRegisterAuthList();
		model.addAttribute("authList", authList);
		return "register/list";
	}
	
	
	@RequestMapping("/startRegister")
	public String startRegister(Model model){
		Register register = newRegisterService.startRegister();
		List<Auth> authList = newRegisterService.getRegisterAuthList();
		model.addAttribute("register", register);
		model.addAttribute("authList", authList);
		return "register/add_register";
	}
	
	@RequestMapping("/stopRegister")
	public String stopRegister(){
		newRegisterService.stopRegister();
		return "redirect:/admin/register/index";
	}
	@RequestMapping("/register")
	@ResponseBody
	public JsonResult<Object> register(int authId,int status){
		newRegisterService.registerAuth(authId, status);
		return new JsonResult<Object>(0,"");
	}
	
//	
//	@RequestMapping("/deleteUser")
//	public String deleteUser(int userId){
//		registerService.deleteUser(userId);
//		return "redirect:/admin/register/index";
//	}
//	@RequestMapping("/addUser")
//	public String addUser(String name,String nick){
//		registerService.addUser(name, nick);
//		return "redirect:/admin/register/index";
//	}
//	@RequestMapping("/autoRegister")
//	@ResponseBody
//	public JsonResult<Object> autoRegister(@RequestParam(defaultValue="false")Boolean flag){
//		this.registerService.setAutoRegisterFlag(flag);
//		return new JsonResult<Object>(0,"",flag);
//	}
	
	@RequestMapping("/getAuthTalk")
	@ResponseBody
	public JsonResult<Object> getAuthTalk(int[] authIds){
		List<JSONObject> list = newRegisterService.getAuthRegisterInfo(authIds);
		return new JsonResult<Object>(0, "", list);
	}
	
	@RequestMapping("/getAuthStatus")
	@ResponseBody
	public JsonResult<Object> getUserTalk(@RequestParam int[] authIds,@RequestParam(defaultValue="-1")int start){
		JSONObject jsonObject = newRegisterService.getAuthRegisterList(authIds, start, 10);
		return new JsonResult<Object>(0, "", jsonObject);
	}
	
	
	
	
}
